import java.util.*;

public class Test {
    public static void main(String[] args) {
        System.out.println("master修改！");
    }
}
class Solution {
    HashMap<Integer,List<Integer>> map;
    int[] record;
    int[] res;
    public int[] findOrder(int numCourses, int[][] prerequisites) {
        map = new HashMap();
        record = new int[numCourses];
        for(int[] pre:prerequisites){
            List<Integer> list = map.getOrDefault(pre[0],new ArrayList());
            list.add(pre[1]);
            map.put(pre[0],list);
        }
        res = new int[0];
        for(int i=0;i<numCourses;i++){
            if(!dfs(new int[numCourses],i))return new int[]{};
            if(record[i]==1)continue;
            res = Arrays.copyOf(res,res.length+1);
            res[res.length-1] = i;
            record[i] = 1;
        }
        return res;
    }
    boolean dfs(int[] path,int cur){
        if(!map.containsKey(cur)||record[cur]==1)return true;
        if(path[cur]==1)return false;
        path[cur] = 1;
        List<Integer> list = map.get(cur);
        for(int num:list){
            if(!dfs(path,num))return false;
            if(record[num]!=1) {
                record[num] = 1;
                res = Arrays.copyOf(res, res.length + 1);
                res[res.length - 1] = num;
            }
        }
        return true;
    }
}